import { defHttp } from '/@/utils/http/axios';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-upms/notify/annountcement/list',
  save = '/api-upms/notify/annountcement/saveOrUpdate',
  edit = '/api-upms/notify/annountcement/saveOrUpdate',
  delete = '/api-upms/notify/annountcement/delete',
  deleteBatch = '/api-upms/notify/annountcement/deleteBatch',
  exportXls = '/api-upms/notify/annountcement/export',
  importExcel = '/api-upms/notify/annountcement/import',
  releaseData = '/api-upms/notify/annountcement/publish/{0}',
  reovkeData = '/api-upms/notify/annountcement/close/{0}',
}

/**
 * 导出url
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入url
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询租户列表
 * @param params
 */
export const getList = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 保存或者更新通告
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 删除通告
 * @param params
 */
export const deleteNotice = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量消息公告
 * @param params
 */
export const batchDeleteNotice = (params) => defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true });

/**
 * 发布
 * @param id
 */
export const doReleaseData = (params) => {
  const url = stringFormat(Api.releaseData, params.id);
  return defHttp.post({ url: url, params });
};
/**
 * 撤销
 * @param id
 */
export const doReovkeData = (params) => {
  const url = stringFormat(Api.reovkeData, params.id);
  return defHttp.post({ url: url, params });
};
